<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>html  &middot; sitename</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">


<meta name="description" content="" />

<meta name="keywords" content="one, two, ">


<meta property="og:title" content="html  &middot; sitename ">
<meta property="og:site_name" content="sitename"/>
<meta property="og:url" content="https://lvzongcheng.gitee.io/webpage/html/" />
<meta property="og:locale" content="en-EN">


<meta property="og:type" content="article" />
<meta property="og:description" content=""/>
<meta property="og:article:published_time" content="2021-04-27T00:00:00Z" />
<meta property="og:article:modified_time" content="2021-04-27T00:00:00Z" />

  
    
<meta property="og:article:tag" content="one">
    
<meta property="og:article:tag" content="two">
    
  

  

<script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "Article",
    "headline": "html",
    "author": {
      "@type": "Person",
      "name": "LvZongCheng"
    },
    "datePublished": "2021-04-27",
    "description": "",
    "wordCount":  477 
  }
</script>



<link rel="canonical" href="https://lvzongcheng.gitee.io/webpage/html/" />

<link rel="apple-touch-icon-precomposed" sizes="144x144" href="https://lvzongcheng.gitee.io/touch-icon-144-precomposed.png">
<link href="https://lvzongcheng.gitee.io/favicon.png" rel="icon">

<meta name="generator" content="Hugo 0.60.0" />

  <!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<link href='https://fonts.googleapis.com/css?family=Merriweather:300%7CRaleway%7COpen+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/css/highlight/default.css">

  
  
	<script>
	  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
	  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

	  ga('create', 'Your Google Analytics tracking code', 'auto');
	  ga('send', 'pageview');

	</script>

</head>
<body>
  <main id="main-wrapper" class="container main_wrapper has-sidebar">
    <header id="main-header" class="container main_header">
  <div class="container brand">
  <div class="container title h1-like">
  <a class="baselink" href="https://lvzongcheng.gitee.io">
  LvZongCheng

</a>

</div>

  
<div class="container topline">
  
  淡定 执著 进取 自律


</div>


</div>

  <nav class="container nav primary no-print">
  

<a class="homelink" href="https://lvzongcheng.gitee.io">home</a>


  
<a href="https://lvzongcheng.gitee.io/framework" title="Show list of Frameworks">Frameworks</a>

<a href="https://lvzongcheng.gitee.io/java" title="Show list of Java">Java</a>

<a href="https://lvzongcheng.gitee.io/linux" title="Show list of Linux">Linux</a>

<a href="https://lvzongcheng.gitee.io/redis" title="Show list of Redis">Redis</a>

<a href="https://lvzongcheng.gitee.io/sql" title="Show list of SQL">SQL</a>

<a href="https://lvzongcheng.gitee.io/Spring" title="Show list of Spring">Spring</a>

<a href="https://lvzongcheng.gitee.io/tools" title="Show list of Tools">Tools</a>

<a href="https://lvzongcheng.gitee.io/webpage" title="Show list of WebPage">WebPage</a>

<a href="https://lvzongcheng.gitee.io/information" title="Show list of information">information</a>

<a href="https://lvzongcheng.gitee.io/network" title="Show list of network">network</a>

<a href="https://lvzongcheng.gitee.io/%E5%BE%AE%E6%9C%8D%E5%8A%A1" title="Show list of 微服务">微服务</a>

<a href="https://lvzongcheng.gitee.io/%E6%80%BB%E7%BB%93" title="Show list of 总结">总结</a>

<a href="https://lvzongcheng.gitee.io/%E6%9C%BA%E5%99%A8%E8%87%AA%E5%8A%A8%E5%8C%96" title="Show list of 机器自动化">机器自动化</a>

<a href="https://lvzongcheng.gitee.io/%E6%B1%87%E7%BC%96" title="Show list of 汇编">汇编</a>

<a href="https://lvzongcheng.gitee.io/%E8%AE%B0%E4%BA%8B%E6%9C%AC" title="Show list of 记事本">记事本</a>


</nav>

<div class="container nav secondary no-print">
  
<a id="contact-link-email" class="contact_link" rel="me" aria-label="Email" href="mailto:Lyc19880405@163.com">
  <span class="fa fa-envelope-square"></span></a>



<a id="contact-link-github" class="contact_link" rel="me" aria-label="Github" href="https://github.com/enten/hugo-boilerplate">
  <span class="fa fa-github-square"></span></a>




 


















</div>


  

</header>


<article id="main-content" class="container main_content single">
  <header class="container hat">
  <h1>html
</h1>

</header>

  <div class="container content">
  <h5 id="html">html符号代码</h5>
<p><code>&amp;nbsp;</code> ：一个字符的半角的不断行的空格，如果需要在网页中插入多个空格，可以将“ ”代码写多遍；
<code>&amp;ensp;</code> ：一个字符的半角的空格，也可以将“ ”写多遍来插入多个空格；
<code>&amp;emsp;</code> ：两个字符的全角的空格，也可以将“ ”写多遍来插入更多的空格；
<code>&amp;thinsp;</code> ：小于一个字符的空格；
<code>&amp;amp;</code> ：和号（&amp;）；
<code>&amp;lt;</code>：小于号（&lt;）；
<code>&amp;gt;</code>：大于号（&gt;）；
<code>&amp;quot;</code>：引号（&quot;）；
<code>&amp;qpos;</code>：撇号（'）;
<code>&amp;copy;</code>：版权符号（）；
<code>&amp;reg;</code>：注册商标符号（）；
<code>&amp;times;</code>：乘号（x）；
<code>&amp;divide;</code>：除号（÷）；</p>
<h5 id="websocket">WebSocket</h5>
<h6 id="heading">客服端代码</h6>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-html" data-lang="html"><span style="color:#75715e">&lt;!DOCTYPE html&gt;</span>
&lt;<span style="color:#f92672">html</span> <span style="color:#a6e22e">xmlns</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;http://www.w3.org/1999/xhtml&#34;</span>&gt;&lt;<span style="color:#f92672">head</span>&gt;
    &lt;<span style="color:#f92672">title</span>&gt;在线客服&lt;/<span style="color:#f92672">title</span>&gt;
    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">http-equiv</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Content-Type&#34;</span> <span style="color:#a6e22e">content</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;text/html; charset=UTF-8&#34;</span> <span style="color:#a6e22e">charset</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;UTF-8&#34;</span>&gt;
    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">name</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;viewport&#34;</span> <span style="color:#a6e22e">content</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no&#34;</span>&gt;
    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">content</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;telephone=no&#34;</span> <span style="color:#a6e22e">name</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;format-detection&#34;</span>&gt;
    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">name</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;apple-touch-fullscreen&#34;</span> <span style="color:#a6e22e">content</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;yes&#34;</span>&gt;
    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">name</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;apple-mobile-web-app-capable&#34;</span> <span style="color:#a6e22e">content</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;yes&#34;</span>&gt;
    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">name</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;apple-mobile-web-app-status-bar-style&#34;</span> <span style="color:#a6e22e">content</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;black&#34;</span>&gt;
    &lt;<span style="color:#f92672">link</span> <span style="color:#a6e22e">href</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;&lt;%=basePath%&gt;wx/send_files/base.css&#34;</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;text/css&#34;</span> <span style="color:#a6e22e">rel</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;stylesheet&#34;</span>&gt;
    &lt;<span style="color:#f92672">link</span> <span style="color:#a6e22e">href</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;&lt;%=basePath%&gt;wx/send_files/index.css&#34;</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;text/css&#34;</span> <span style="color:#a6e22e">rel</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;stylesheet&#34;</span>&gt;
    &lt;<span style="color:#f92672">link</span> <span style="color:#a6e22e">rel</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;stylesheet&#34;</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;text/css&#34;</span> <span style="color:#a6e22e">href</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;&lt;%=basePath%&gt;wx/send_files/kfmain.css&#34;</span>&gt;
   
&lt;/<span style="color:#f92672">head</span>&gt;
&lt;<span style="color:#f92672">body</span> &gt;
 Welcome&lt;<span style="color:#f92672">br</span>/&gt;
    &lt;<span style="color:#f92672">input</span> <span style="color:#a6e22e">id</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;text&#34;</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;text&#34;</span> /&gt;&lt;<span style="color:#f92672">button</span> <span style="color:#a6e22e">onclick</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;send()&#34;</span>&gt;Send&lt;/<span style="color:#f92672">button</span>&gt;    &lt;<span style="color:#f92672">button</span> <span style="color:#a6e22e">onclick</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;closeWebSocket()&#34;</span>&gt;Close&lt;/<span style="color:#f92672">button</span>&gt;
    &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">id</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;message&#34;</span>&gt;
    &lt;/<span style="color:#f92672">div</span>&gt;
  &lt;/<span style="color:#f92672">body</span>&gt;
   
  &lt;<span style="color:#f92672">script</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;text/javascript&#34;</span>&gt;
      <span style="color:#66d9ef">var</span> <span style="color:#a6e22e">websocket</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">null</span>;
       
      <span style="color:#75715e">//判断当前浏览器是否支持WebSocket
</span><span style="color:#75715e"></span>      <span style="color:#66d9ef">if</span>(<span style="color:#e6db74">&#39;WebSocket&#39;</span> <span style="color:#66d9ef">in</span> window){
          <span style="color:#a6e22e">websocket</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">WebSocket</span>(<span style="color:#e6db74">&#34;ws://localhost:8080/WebSocketTest/websocket&#34;</span>);
      }
      <span style="color:#66d9ef">else</span>{
          <span style="color:#a6e22e">alert</span>(<span style="color:#e6db74">&#39;Not support websocket&#39;</span>)
      }
       
      <span style="color:#75715e">//连接发生错误的回调方法
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">websocket</span>.<span style="color:#a6e22e">onerror</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">function</span>(){
          <span style="color:#a6e22e">setMessageInnerHTML</span>(<span style="color:#e6db74">&#34;error&#34;</span>);
      };
       
      <span style="color:#75715e">//连接成功建立的回调方法
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">websocket</span>.<span style="color:#a6e22e">onopen</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">function</span>(<span style="color:#a6e22e">event</span>){
          <span style="color:#a6e22e">setMessageInnerHTML</span>(<span style="color:#e6db74">&#34;open&#34;</span>);
      }
       
      <span style="color:#75715e">//接收到消息的回调方法
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">websocket</span>.<span style="color:#a6e22e">onmessage</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">function</span>(<span style="color:#a6e22e">event</span>){
          <span style="color:#a6e22e">setMessageInnerHTML</span>(<span style="color:#a6e22e">event</span>.<span style="color:#a6e22e">data</span>);
      }
       
      <span style="color:#75715e">//连接关闭的回调方法
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">websocket</span>.<span style="color:#a6e22e">onclose</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">function</span>(){
          <span style="color:#a6e22e">setMessageInnerHTML</span>(<span style="color:#e6db74">&#34;close&#34;</span>);
      }
       
      <span style="color:#75715e">//监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
</span><span style="color:#75715e"></span>      window.<span style="color:#a6e22e">onbeforeunload</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">function</span>(){
          <span style="color:#a6e22e">websocket</span>.<span style="color:#a6e22e">close</span>();
      }
       
      <span style="color:#75715e">//将消息显示在网页上
</span><span style="color:#75715e"></span>      <span style="color:#66d9ef">function</span> <span style="color:#a6e22e">setMessageInnerHTML</span>(<span style="color:#a6e22e">innerHTML</span>){
          document.<span style="color:#a6e22e">getElementById</span>(<span style="color:#e6db74">&#39;message&#39;</span>).<span style="color:#a6e22e">innerHTML</span> <span style="color:#f92672">+=</span> <span style="color:#a6e22e">innerHTML</span> <span style="color:#f92672">+</span> <span style="color:#e6db74">&#39;&lt;br/&gt;&#39;</span>;
      }
       
      <span style="color:#75715e">//关闭连接
</span><span style="color:#75715e"></span>      <span style="color:#66d9ef">function</span> <span style="color:#a6e22e">closeWebSocket</span>(){
          <span style="color:#a6e22e">websocket</span>.<span style="color:#a6e22e">close</span>();
      }
       
      <span style="color:#75715e">//发送消息
</span><span style="color:#75715e"></span>      <span style="color:#66d9ef">function</span> <span style="color:#a6e22e">send</span>(){
          <span style="color:#66d9ef">var</span> <span style="color:#a6e22e">message</span> <span style="color:#f92672">=</span> document.<span style="color:#a6e22e">getElementById</span>(<span style="color:#e6db74">&#39;text&#39;</span>).<span style="color:#a6e22e">value</span>;
          <span style="color:#a6e22e">websocket</span>.<span style="color:#a6e22e">send</span>(<span style="color:#a6e22e">message</span>);
      }
  &lt;/<span style="color:#f92672">script</span>&gt;
</code></pre></div><h6 id="heading1">服务端代码</h6>
<ul>
<li><strong>注解驱动的方法</strong></li>
</ul>
<pre><code>package Lvc.test.testSocket;

import java.io.IOException;
import java.util.concurrent.CopyOnWriteArraySet;

import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

//注解驱动的方法
//将目前的类定义成一个websocket服务器端
@ServerEndpoint(&quot;/websocket&quot;)
public class WebSocketTest {
	//静态变量，用来记录当前在线连接数。应该把它设计成线程安全的。
    private static int onlineCount = 0;
     
    //concurrent包的线程安全Set，用来存放每个客户端对应的MyWebSocket对象。若要实现服务端与单一客户端通信的话，可以使用Map来存放，其中Key可以为用户标识
    private static CopyOnWriteArraySet&lt;WebSocketTest&gt; webSocketSet = new CopyOnWriteArraySet&lt;WebSocketTest&gt;();
     
    //与某个客户端的连接会话，需要通过它来给客户端发送数据
    private Session session;
     
    /**
     * 连接建立成功调用的方法
     * @param session  可选的参数。session为与某个客户端的连接会话，需要通过它来给客户端发送数据
     */
    @OnOpen
    public void onOpen(Session session){
        this.session = session;
        webSocketSet.add(this);     //加入set中
        addOnlineCount();           //在线数加1
        System.out.println(&quot;有新连接加入！当前在线人数为&quot; + getOnlineCount());
    }
     
    /**
     * 连接关闭调用的方法
     */
    @OnClose
    public void onClose(){
        webSocketSet.remove(this);  //从set中删除
        subOnlineCount();           //在线数减1    
        System.out.println(&quot;有一连接关闭！当前在线人数为&quot; + getOnlineCount());
    }
     
    /**
     * 收到客户端消息后调用的方法
     * @param message 客户端发送过来的消息
     * @param session 可选的参数
     */
    @OnMessage
    public void onMessage(String message, Session session) {
        System.out.println(&quot;来自客户端的消息:&quot; + message);
         
        //群发消息
        for(WebSocketTest item: webSocketSet){             
            try {
                item.sendMessage(message);
            } catch (IOException e) {
                e.printStackTrace();
                continue;
            }
        }
    }
     
    /**
     * 发生错误时调用
     * @param session
     * @param error
     */
    @OnError
    public void onError(Session session, Throwable error){
        System.out.println(&quot;发生错误&quot;);
        error.printStackTrace();
    }
     
    /**
     * 这个方法与上面几个方法不一样。没有用注解，是根据自己需要添加的方法。
     * @param message
     * @throws IOException
     */
    public void sendMessage(String message) throws IOException{
        this.session.getBasicRemote().sendText(message);
        //this.session.getAsyncRemote().sendText(message);
    }
 
    public static synchronized int getOnlineCount() {
        return onlineCount;
    }
 
    public static synchronized void addOnlineCount() {
    	WebSocketTest.onlineCount++;
    }
     
    public static synchronized void subOnlineCount() {
    	WebSocketTest.onlineCount--;
    }
}
</code></pre><ul>
<li><strong>界面驱动方法</strong></li>
</ul>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#f92672">package</span> Lvc.test.testSocket<span style="color:#f92672">;</span>

<span style="color:#f92672">import</span> java.io.IOException<span style="color:#f92672">;</span>

<span style="color:#f92672">import</span> javax.websocket.CloseReason<span style="color:#f92672">;</span>
<span style="color:#f92672">import</span> javax.websocket.Endpoint<span style="color:#f92672">;</span>
<span style="color:#f92672">import</span> javax.websocket.EndpointConfig<span style="color:#f92672">;</span>
<span style="color:#f92672">import</span> javax.websocket.MessageHandler<span style="color:#f92672">;</span>
<span style="color:#f92672">import</span> javax.websocket.Session<span style="color:#f92672">;</span>

<span style="color:#75715e">//界面驱动方法 
</span><span style="color:#75715e"></span><span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">WebSocketTest</span> <span style="color:#66d9ef">extends</span> Endpoint <span style="color:#f92672">{</span>

	<span style="color:#a6e22e">@Override</span>
	<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">void</span> <span style="color:#a6e22e">onOpen</span><span style="color:#f92672">(</span>Session session<span style="color:#f92672">,</span> EndpointConfig endpointConfig<span style="color:#f92672">)</span> <span style="color:#f92672">{</span>
		<span style="color:#66d9ef">final</span> Session mySession <span style="color:#f92672">=</span> session<span style="color:#f92672">;</span>
		
		mySession<span style="color:#f92672">.</span><span style="color:#a6e22e">addMessageHandler</span><span style="color:#f92672">(</span><span style="color:#66d9ef">new</span> MessageHandler<span style="color:#f92672">.</span><span style="color:#a6e22e">Whole</span><span style="color:#f92672">&lt;</span>String<span style="color:#f92672">&gt;</span><span style="color:#f92672">(</span><span style="color:#f92672">)</span> <span style="color:#f92672">{</span>
			<span style="color:#a6e22e">@Override</span>
			<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">void</span> <span style="color:#a6e22e">onMessage</span><span style="color:#f92672">(</span>String text<span style="color:#f92672">)</span> <span style="color:#f92672">{</span>
				<span style="color:#66d9ef">try</span> <span style="color:#f92672">{</span>
					mySession<span style="color:#f92672">.</span><span style="color:#a6e22e">getBasicRemote</span><span style="color:#f92672">(</span><span style="color:#f92672">)</span><span style="color:#f92672">.</span><span style="color:#a6e22e">sendText</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;吕宗诚：&#34;</span><span style="color:#f92672">+</span>text<span style="color:#f92672">)</span><span style="color:#f92672">;</span>
				<span style="color:#f92672">}</span> <span style="color:#66d9ef">catch</span> <span style="color:#f92672">(</span>IOException ioe<span style="color:#f92672">)</span> <span style="color:#f92672">{</span>
					System<span style="color:#f92672">.</span><span style="color:#a6e22e">out</span><span style="color:#f92672">.</span><span style="color:#a6e22e">println</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;oh dear, something went wrongtrying to send the message back: &#34;</span> <span style="color:#f92672">+</span>
							ioe<span style="color:#f92672">.</span><span style="color:#a6e22e">getMessage</span><span style="color:#f92672">(</span><span style="color:#f92672">)</span><span style="color:#f92672">)</span><span style="color:#f92672">;</span>
				<span style="color:#f92672">}</span>
			<span style="color:#f92672">}</span>
		<span style="color:#f92672">}</span><span style="color:#f92672">)</span><span style="color:#f92672">;</span>

	<span style="color:#f92672">}</span>

	<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">void</span> <span style="color:#a6e22e">onClose</span><span style="color:#f92672">(</span>Session session<span style="color:#f92672">,</span> CloseReason closeReason<span style="color:#f92672">)</span> <span style="color:#f92672">{</span>
			System<span style="color:#f92672">.</span><span style="color:#a6e22e">out</span><span style="color:#f92672">.</span><span style="color:#a6e22e">println</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Close&#34;</span><span style="color:#f92672">)</span><span style="color:#f92672">;</span>
	<span style="color:#f92672">}</span>
	<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">void</span> <span style="color:#a6e22e">onError</span> <span style="color:#f92672">(</span>Session session<span style="color:#f92672">,</span> Throwable throwable<span style="color:#f92672">)</span> <span style="color:#f92672">{</span>
		System<span style="color:#f92672">.</span><span style="color:#a6e22e">out</span><span style="color:#f92672">.</span><span style="color:#a6e22e">println</span><span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Error&#34;</span><span style="color:#f92672">)</span><span style="color:#f92672">;</span>
	<span style="color:#f92672">}</span>

<span style="color:#f92672">}</span>

</code></pre></div><div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#f92672">package</span> Lvc.test.testSocket<span style="color:#f92672">;</span>

<span style="color:#f92672">import</span> java.util.HashSet<span style="color:#f92672">;</span>
<span style="color:#f92672">import</span> java.util.Set<span style="color:#f92672">;</span>

<span style="color:#f92672">import</span> javax.websocket.Endpoint<span style="color:#f92672">;</span>
<span style="color:#f92672">import</span> javax.websocket.server.ServerApplicationConfig<span style="color:#f92672">;</span>
<span style="color:#f92672">import</span> javax.websocket.server.ServerEndpointConfig<span style="color:#f92672">;</span>

<span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">ProgrammaticEchoServerAppConfig</span> <span style="color:#66d9ef">implements</span> ServerApplicationConfig<span style="color:#f92672">{</span>

	<span style="color:#a6e22e">@Override</span>
	<span style="color:#66d9ef">public</span> Set<span style="color:#f92672">&lt;</span>ServerEndpointConfig<span style="color:#f92672">&gt;</span> <span style="color:#a6e22e">getEndpointConfigs</span><span style="color:#f92672">(</span>Set<span style="color:#f92672">&lt;</span>Class<span style="color:#f92672">&lt;</span><span style="color:#f92672">?</span> <span style="color:#66d9ef">extends</span> Endpoint<span style="color:#f92672">&gt;</span><span style="color:#f92672">&gt;</span> endpointClasses<span style="color:#f92672">)</span> <span style="color:#f92672">{</span>
		HashSet<span style="color:#f92672">&lt;</span>ServerEndpointConfig<span style="color:#f92672">&gt;</span> configs <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> HashSet<span style="color:#f92672">&lt;</span>ServerEndpointConfig<span style="color:#f92672">&gt;</span><span style="color:#f92672">(</span><span style="color:#f92672">)</span><span style="color:#f92672">;</span>
		ServerEndpointConfig sec <span style="color:#f92672">=</span>ServerEndpointConfig<span style="color:#f92672">.</span><span style="color:#a6e22e">Builder</span><span style="color:#f92672">.</span><span style="color:#a6e22e">create</span><span style="color:#f92672">(</span>WebSocketTest<span style="color:#f92672">.</span><span style="color:#a6e22e">class</span><span style="color:#f92672">,</span> <span style="color:#e6db74">&#34;/websocket&#34;</span><span style="color:#f92672">)</span><span style="color:#f92672">.</span><span style="color:#a6e22e">build</span><span style="color:#f92672">(</span><span style="color:#f92672">)</span><span style="color:#f92672">;</span>
		configs<span style="color:#f92672">.</span><span style="color:#a6e22e">add</span><span style="color:#f92672">(</span>sec<span style="color:#f92672">)</span><span style="color:#f92672">;</span>
		<span style="color:#66d9ef">return</span> configs<span style="color:#f92672">;</span>
	<span style="color:#f92672">}</span>

	<span style="color:#a6e22e">@Override</span>
	<span style="color:#66d9ef">public</span> Set<span style="color:#f92672">&lt;</span>Class<span style="color:#f92672">&lt;</span><span style="color:#f92672">?</span><span style="color:#f92672">&gt;</span><span style="color:#f92672">&gt;</span> getAnnotatedEndpointClasses<span style="color:#f92672">(</span>Set<span style="color:#f92672">&lt;</span>Class<span style="color:#f92672">&lt;</span><span style="color:#f92672">?</span><span style="color:#f92672">&gt;</span><span style="color:#f92672">&gt;</span> scanned<span style="color:#f92672">)</span><span style="color:#f92672">{</span>
		<span style="color:#66d9ef">return</span> scanned<span style="color:#f92672">;</span>
	<span style="color:#f92672">}</span>



<span style="color:#f92672">}</span>

</code></pre></div>
</div>


  
</article>
      <footer id="main-footer" class="container main_footer">
  

  <div class="container nav foot no-print">
  
<a href="https://lvzongcheng.gitee.io/license">license</a>


  <a class="toplink" href="#">back to top</a>

</div>

  <div class="container credits">
  
<div class="container footline">
  
  code with <!-- raw HTML omitted --><!-- raw HTML omitted -->


</div>


  
<div class="container copyright">
  
  (c) 2015 yourname.


</div>


</div>

</footer>

    </main>
    
<script type="text/javascript">
  (function() {
    
    
    if (window.location.hostname == "localhost")
      return;
    var dsq = document.createElement('script'); dsq.async = true; dsq.type = 'text/javascript';
    dsq.src = '//your_disqus_shortname.disqus.com/count.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
</script>



<script src="/js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>



    
  </body>
</html>

